#@layout()

#define content()

<div class="easyui-layout" data-options="fit:true">
    <div data-options="region:'center',border:true">
        <div id="datagridId"></div>

        <div id="datagridTb">
            <div class="row">
                <div class="col-md-12">
                    <form id="searchForm">
                        <div class="easyui-panel" title="信息查询" style="width:100%;padding:10px;"
                             data-options="iconCls:'icon-application_form'">

                            <!--统计类型：-->
                            <!--<select name="staType" id="staType" class="easyui-combobox" data-options="editable: false">-->
                                <!--<option value="regCount" selected>注册</option>-->
                                <!--<option value="verify">认证</option>-->
                                <!--<option value="logoutCount">注销</option>-->
                            <!--</select>-->
                            <!--认证类型：-->
                            <!--<select name="authType" id="authType" class="easyui-combobox" data-options="editable: false">-->
                                <!--#for(dict : authTypeListForJS)-->
                                <!--<option value="#(dict.dictText)">#(dict.dictName)</option>-->
                                <!--#end-->
                            <!--</select>-->
                            开始时间: <input class="easyui-datebox" id="startDate" value="#(startDate)" data-options="required:true,editable:false"
                                         style="width:110px">&nbsp;&nbsp;
                            结束时间: <input class="easyui-datebox" id="endDate" value="#(endDate)" data-options="required:true,editable:false"
                                         style="width:110px">&nbsp;&nbsp;
                            安全级别:
                            <select name="aaidType" id="aaidType" class="easyui-combobox" data-options="editable: false">
                                <option value="#(com.gmrz.uap.cfg.SystemConst :: CERT_SECURE_LEVEL_SE)">#(com.gmrz.uap.cfg.SystemConst :: CERT_SECURE_LEVEL_SE)</option>
                                <option value="#(com.gmrz.uap.cfg.SystemConst :: CERT_SECURE_LEVEL_TEEANDTUI)">#(com.gmrz.uap.cfg.SystemConst :: CERT_SECURE_LEVEL_TEEANDTUI)</option>
                                <option value="#(com.gmrz.uap.cfg.SystemConst :: CERT_SECURE_LEVEL_TEE)">#(com.gmrz.uap.cfg.SystemConst :: CERT_SECURE_LEVEL_TEE)</option>
                            </select>&nbsp;&nbsp;
                            渠道：
                            <select name="tenantId" id="tenantId" class="easyui-combobox" data-options="editable: false">
                                #for(tenant : tenants)
                                    #(tenant)
                                #end
                            </select>&nbsp;&nbsp;
                            厂商：
                            <select id="deviceType" name="deviceType" class="easyui-combobox" data-options="editable: false">
                                <option value="ALL" selected>全部</option>
                                #for(deviceType : deviceTypes)
                                <option value="#(deviceType)">#(deviceType)</option>
                                #end
                            </select>&nbsp;&nbsp;
                            型号：
                            <select name="deviceName" id="deviceName" class="easyui-combobox" data-options="editable: false">
                                <option value="ALL" selected>全部</option>
                                #for(deviceName : deviceNames)
                                <option value="#(deviceName)">#(deviceName)</option>
                                #end
                            </select>
                            <a href="javascript:;" class="easyui-linkbutton" data-options="plain:true"
                               onclick="datagridQuery();" iconCls="icon-zoom">#(_res.get('system.common.search'))</a>
                            <a href="javascript:;" class="easyui-linkbutton" data-options="plain:true"
                               onclick="$('#searchForm').form('clear');" iconCls="icon-zoom_out">#(_res.get('system.common.clear'))</a>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>


</div>

#end


#define css()

#end


#define js()

<script type="text/javascript">

    var _datagrid = "datagridId", _form = "formId", _datagridTb = "datagridTb";
    var datagridListUrl = contextRootPath + '/dataStatistics/getCertRegister';

    $(function () {
        //初始化表格
        $("#" + _datagrid).datagrid({
            url: datagridListUrl,
            fit: true,
            border: false,
            rownumbers: true,
            pageSize: 20,
            toolbar: '#' + _datagridTb,
            singleSelect: false,
            pagination: true,
            nowrap: false,
            striped: true,
            fitColumns: true,
            queryParams: {
                'tenantId': $('#tenantId').val(),
                'aaidType': $('#aaidType').val(),
                'deviceTypeAlias': $('#deviceType').val(),
                'deviceNameAlias': $('#deviceName').val(),
                'startDate': $('#startDate').val(),
                'endDate': $('#endDate').val()
            },
            columns: [[
                {
                    field: DBConts.TABLE_DATA_STATISTICS.TENANT_ID,
                    title: "渠道",
                    sortable: false
//                    formatter: function (value, row, index) {
//                        if(value === 'regCount') return '注册';
//
//                        if(value === 'verify') return '认证';
//
//                        if(value === 'logoutCount') return '注销';
//                    }
                },
                {
                    field: "aaid_type",
                    title: "安全级别",
                    sortable: false
//                    formatter: function (value, row, index) {
//                        return getAuthType(value);
//                    }
                },
                {
                    field: DBConts.TABLE_DATA_STATISTICS.DEVICE_TYPE,
                    title: "厂商别名",
                    sortable: false
                },
                {
                    field: DBConts.TABLE_DATA_STATISTICS.DEVICE_NAME,
                    title: "型号别名",
                    sortable: false,
                    formatter: function (value, row, index) {
                        //return value;
                        if(value === '其他') {
                            var k = 'tenantId='+$('#tenantId').val()+
                                '&aaidType='+$('#aaidType').val()+
                                '&deviceTypeAlias='+$('#deviceType').val()+
                                '&deviceNameAlias='+$('#deviceName').combobox('getValue')+
                                '&startDate='+$('#startDate').val()+
                                '&endDate='+$('#endDate').val();
                            return '<a href=\'javascript:void(0);\' onclick=\'displayInfo(this)\' class=\'easyui-linkbutton\' value=\'' + k + '\'>' + value + '</a>';
                        }else {
                            return value;
                        }
                    }
                },
                {
                    field: DBConts.TABLE_DATA_STATISTICS.STA_COUNT,
                    title: "数量",
                    sortable: false
                }
            ]]
        });
    });


    function datagridQuery() {
//        var flag = $("#searchForm").form('enableValidation').form('validate');
//
//        if (!flag) return;
        var startDate = $('#startDate').val();
        var endDate = $('#endDate').val();

        if(startDate === '' || startDate === null){
            $.messager.alert('警告','开始时间不能为空','warning');
            return;
        }

        if(endDate === '' || endDate === null){
            $.messager.alert('警告','结束时间不能为空','warning');
            return;
        }
        var starttime = new Date(Date.parse(startDate));
        var endtime = new Date(Date.parse(endDate));

        if(starttime > endtime){
            $.messager.alert('警告','开始时间不能大于结束时间','warning');
            return;
        }
        var v =  $('#deviceName').combobox('getValue');

        var tenantId = $('#tenantId').val()
        if(tenantId === '' || tenantId === null){
            $.messager.alert('警告','渠道不能为空','warning');
            return;
        }

        var aaidType = $('#aaidType').val();
        if(aaidType === '' || aaidType === null){
            $.messager.alert('警告','安全级别不能为空','warning');
            return;
        }

        var dType = $('#deviceType').val();
        if(dType === '' || dType === null){
            $.messager.alert('警告','厂商不能为空','warning');
            return;
        }

        var dName = $('#deviceName').combobox('getValue');
        if(dName === '' || dName === null){
            $.messager.alert('警告','型号不能为空','warning');
            return;
        }

        $("#" + _datagrid).datagrid({
            queryParams: {
                'tenantId': $('#tenantId').val(),
                'aaidType': $('#aaidType').val(),
                'deviceTypeAlias': $('#deviceType').val(),
                'deviceNameAlias': $('#deviceName').combobox('getValue'),
                'startDate': $('#startDate').val(),
                'endDate': $('#endDate').val()
            }
        });
    }


    $("#deviceType").combobox({
        onSelect:function (selectObj) {
            getDeviceNameAlias(selectObj.value);
        }
    });

    function getDeviceNameAlias(deviceType) {

        $("#deviceName").combobox({
            url: contextRootPath + "/dataStatistics/getDeviceNameAliasList?deviceTypeAlias="+deviceType,
            method: 'get',
            valueField: 'deviceNameAlias',
            textField: 'deviceNameAliasDesc',
            panelHeight: 'auto',
            width:'100px',
            editable: false
        });
    }


    function displayInfo(obj) {
        var value = obj.getAttribute("value");
        console.log(value);
        var r = '';
        $.ajax({
            type: 'get',
            url: contextRootPath + "/dataStatistics/getOtherDeviceNameAliasList?"+value,
            async: false,
            dataType: 'json',
            success: function (data) {
                r = data;
            }
        });

        var tableStr = '<table class="table table-bordered"><tr><th>厂商</th><th>型号</th></tr>';
        var jsonObj = r;
        for(var i in jsonObj){
            var trStr = '<tr><td>'+ jsonObj[i].device_type +'</td><td>' +jsonObj[i].device_name +'</td></tr>';
            tableStr = tableStr + trStr;
        }

        tableStr = tableStr +'</table>';


        var element = $('<div></div>');
        element.attr('id', 'fidoInfoDlg');
        element.appendTo(document.body);
        element.dialog({
            title: '详细信息',
            content: '<pre style="width: 100%;line-height: 1.5em;">' + tableStr + '</pre>',
            width: $(window).width() - 250,
            height: $(window).height() - 50,
            modal: true,
            onClose: function () {
                $(this).dialog("destroy");
            }
        });
    }
</script>

#end



